﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using AppAds_API.BLL.Interface;
using AppAds_API.BLL.Repository;
using AppAds_API.BLL.Model;
using Microsoft.Practices.Unity;

namespace AppAds_API.Controllers
{
    public class AdsMainController : ApiController
    {
        static readonly IAdsRepository _repository = new AdsRepository();

        public IEnumerable<Ad> GetAllAds()
        {
            return _repository.GetAllAds();
        }

        public IEnumerable<Ad> GetAdsByCategory(string cat)
        {
            return _repository.GetAdsByType(cat);
        }

        public Ad GetAdById(int id)
        {
            Ad item = _repository.GetAdById(id);
            if (item == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }
            return item;
        }
    }
}